package com.xxxx.controller;

import com.xxxx.pojo.HouseKeeper;
import com.xxxx.pojo.Type;
import com.xxxx.service.IndexService;
import com.xxxx.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.xxxx.pojo.ResponseResult;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author Lionel
 * @Date 2021/3/8 1:41
 * Created by IntelliJ IDEA 2020.1.
 * Project: house
 * Description：首页Controller
 */
@Controller
@RequestMapping("/index")
public class IndexController extends BaseController{

    @Autowired
    private IndexService indexService;

    /**
     * 跳转主页
     * @return 主页
     */
    @GetMapping("/toIndex")
    public String toIndex() {
        return "index";
    }

    @RequestMapping("/getAllType")
    @ResponseBody
    public ResponseResult<List<Type>> getAllType () {
        ResponseResult<List<Type>> result = new ResponseResult<>();
        List<Type> list = indexService.getAllType();
        System.out.println(list);
        result.setData(list);
        return result;
    }

    @RequestMapping("/getAllSmallType")
    @ResponseBody
    public ResponseResult<List<Type>> getAllSmallType (
            @RequestParam("type_id") Integer type_id
    ) {
        ResponseResult<List<Type>> result = new ResponseResult<>();
        List<Type> list = indexService.getAllSmallType(type_id);
        result.setData(list);
        return result;
    }

    @RequestMapping("/getTopHousekeeper")
    @ResponseBody
    public ResponseResult<List<HouseKeeper>> getTopHouseKeeper () {
        ResponseResult<List<HouseKeeper>> result = new ResponseResult<>();
        List<HouseKeeper> list = indexService.getTopHousekeeper(5);
        result.setData(list);
        return result;
    }

    @RequestMapping("/getTopRepair")
    @ResponseBody
    public ResponseResult<List<HouseKeeper>> getTopRepair () {
        ResponseResult<List<HouseKeeper>> result = new ResponseResult<>();
        List<HouseKeeper> list = indexService.getTopHousekeeper(9);
        result.setData(list);
        return result;
    }

    @RequestMapping("/getTopMove")
    @ResponseBody
    public ResponseResult<List<HouseKeeper>> getTopMove () {
        ResponseResult<List<HouseKeeper>> result = new ResponseResult<>();
        List<HouseKeeper> list = indexService.getTopHousekeeper(13);
        result.setData(list);
        return result;
    }

    @RequestMapping("/getRecommend")
    @ResponseBody
    public ResponseResult<List<HouseKeeper>> getRecommend (
            HttpSession session
    ) {
        ResponseResult<List<HouseKeeper>> result = new ResponseResult<>();
        List<HouseKeeper> list = indexService.getRecommend(session);
        result.setData(list);
        return result;
    }

    @PostMapping("/getTypeID")
    @ResponseBody
    public ResponseResult<Integer> getTypeID (
            @RequestParam("param") String param
    ) {
        ResponseResult<Integer> result = new ResponseResult<>();
        int id = indexService.getTypeID(param);
        result.setData(id);
        return result;
    }

}
